package com.atguigu.gulimall.search.controller;

import com.atguigu.gulimall.search.service.MallSearchService;
import com.atguigu.gulimall.search.vo.SearchParam;
import com.atguigu.gulimall.search.vo.SearchResult;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {

    @Resource
    private MallSearchService mallSearchService;

    @RequestMapping("/list.html")
    public String phone(SearchParam searchParam, Model model, HttpServletRequest request){
        //1.根据传递过来的页面的查询参数，去es中检索商品
        String queryString = request.getQueryString();
        searchParam.setQueryString(queryString);
        SearchResult result = mallSearchService.search(searchParam);

        model.addAttribute("result",result);
        return "list";
    }
}
